package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterCeptor;
import cn.tedu._06interceptor.interceptors.MyInterCeptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器并添加拦截规则
        //配置方案1：拦截所有的请求
        //registry.addInterceptor(new MyInterCeptor());
        //配置方案2：拦截指定的请求
       // registry.addInterceptor(new MyInterCeptor()).addPathPatterns("/users/**");
        //配置方案3:排除指定的请求
//        registry.addInterceptor(new MyInterCeptor()).addPathPatterns("/users/**").excludePathPatterns("/users/login");

        //多个拦截器
        registry.addInterceptor(new MyInterCeptor());
        registry.addInterceptor(new MyInterCeptor2());


    }
}
